package com.example.administrator.x3picturetransliteration.Home.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.R;

public class ExamplesDialog extends Dialog {

    private String title;
    private String content;

    private hd mhd;

    public ExamplesDialog(@NonNull Context context,String title,String content,hd mhd) {
        super(context, R.style.HomeDialog);

        this.title = title;
        this.content = content;
        this.mhd = mhd;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_dialog_examples);
        getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);//设置全屏

        ((TextView)findViewById(R.id.ContentText)).setText(content);
        ((TextView)findViewById(R.id.TitleText)).setText(title);

        ((ImageView)findViewById(R.id.LButton)).setImageResource(R.mipmap.home_shape3);
        ((ImageView)findViewById(R.id.LButton)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ExamplesDialog.this.dismiss();
            }
        });

        ((ImageView)findViewById(R.id.img)).setImageResource("WORD示例".equals(title)?R.drawable.img_sl1:R.drawable.img_sl2);

        ((TextView)findViewById(R.id.okText)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mhd.hdff();
                ExamplesDialog.this.dismiss();
            }
        });

    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity= Gravity.CENTER;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height= WindowManager.LayoutParams.MATCH_PARENT;

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);

    }

    public interface hd{

        void hdff();
    }
}
